<extend name="Layout:ly1"/>

<block name="head">
    <script>
        $(document).ready(function () {
            var Table = $('table');
            var DataTable = Table.DataTable({
                language: dataTables_zh_CN,
                pageLength: 100
            });
            Table.find('tbody').on('click','tr',function(){
                $(this).toggleClass('active');
            });
            $(".select_all").on('click',function(){
                Table.find('tbody tr').addClass('active');
            });
            $(".select_null").on('click',function(){
                Table.find('tbody tr').removeClass('active');
            });
            $(".select_backup").on('click',function(){
                var select_tables = [];
                DataTable.rows('.active').data().each(function(data,index){
                    select_tables[index] = data;
                });
                if(select_tables.length<1){
                    layer.alert("请选择至少一个数据库");
                    return false;
                }
                var url = "{:U('Admin/System/dataBackup')}";
                var layer_load = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                $.ajax({
                    type:"post",
                    url:url,
                    data:{select_tables:select_tables},
                    success: function (msg) {
                        if(msg>0){
                            layer.close(layer_load);
                            layer.alert("备份成功，大小: "+msg+"bts",{
                                time:2000
                            });
                            location.href = "{:U('Admin/System/dataReduction')}";
                        }
                    }
                });
            });
        });
    </script>
</block>

<block name="body">
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">数据备份</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        数据表列表
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>表名</th>
                                    <th>数据</th>
                                    <th>容量</th>
                                </tr>
                                </thead>
                                <tbody>
                                <foreach name="select_tables" item="v" key="k" >
                                    <tr data-name="{$v['table_name']}">
                                        <td>{$v['table_name']}</td>
                                        <td>{$v['table_count']}</td>
                                        <td>{$v['table_size']}</td>
                                    </tr>
                                </foreach>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                        <div><button class="btn btn-primary select_all">全选</button> <button class="btn btn-info select_null">全不选</button> <button class="btn btn-success select_backup">备份所选</button></div>
                    </div>
                    <!-- /.panel-body -->
                </div>
            </div>
        </div>
    </div>
</block>